import { ElRadioGroup, ElRadio } from 'element-plus';
import storeDict from '../../../store/sessionStorageDict/index'
const dictData = storeDict()

const RadioGroup = (config, params) => {
    if(config.hasOwnProperty('dict')) {
        dictData.getDict(config.dict)
        return (
            <ElRadioGroup {...config.labelProps} v-model={params[config.props.prop]}>
                {
                    handleFilterData(dictData.dictData[config.dict]).map(v => {
                        return (
                            <ElRadio label={v.value} v-slots={v.label}></ElRadio>
                        )
                    })
                }
            </ElRadioGroup>
        )
    }else {
        return (
            <ElRadioGroup {...config.labelProps} v-model={params[config.props.prop]}>
                {
                    config.options.map(v => {
                        return (
                            <ElRadio label={v.value} v-slots={v.label}></ElRadio>
                        )
                    })
                }
            </ElRadioGroup>
        )
    }
}
// 处理 options 数据
function handleFilterData(dictData) {
    console.log(dictData, 'dictData')
    return dictData.map(item => {
        return {
            label: item.dictLabel,
            value: item.dictValue
        }
    })
}
export default RadioGroup
